package com.sinothk.special.buyer.userblog.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sinothk.special.buyer.userblog.entity.UserBlogVisitor;
import com.sinothk.special.buyer.userblog.service.IUserBlogVisitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

 /**
 * @Description: 个人博客访问者
 * @Author: Liangyt
 * @Date:   2022-06-06
 * @Version: V1.0
 */
@Api(tags="个人博客访问者")
@RestController
@RequestMapping("/blog/userBlogVisitor")
@Slf4j
public class UserBlogVisitorController{
	@Autowired
	private IUserBlogVisitorService userBlogVisitorService;
	
	/**
	 * 分页列表查询
	 *
	 * @param userBlogVisitor
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "个人博客访问者-分页列表查询")
	@ApiOperation(value="个人博客访问者-分页列表查询", notes="个人博客访问者-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(UserBlogVisitor userBlogVisitor,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<UserBlogVisitor> queryWrapper = QueryGenerator.initQueryWrapper(userBlogVisitor, req.getParameterMap());
		Page<UserBlogVisitor> page = new Page<UserBlogVisitor>(pageNo, pageSize);
		IPage<UserBlogVisitor> pageList = userBlogVisitorService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
//	/**
//	 *   添加
//	 *
//	 * @param userBlogVisitor
//	 * @return
//	 */
//	@AutoLog(value = "个人博客访问者-添加")
//	@ApiOperation(value="个人博客访问者-添加", notes="个人博客访问者-添加")
//	@PostMapping(value = "/add")
//	public Result<?> add(@RequestBody UserBlogVisitor userBlogVisitor) {
//		userBlogVisitorService.save(userBlogVisitor);
//		return Result.OK("添加成功！");
//	}
	 /**
	  * 个人博客访问者-添加
	  *
	  * @param blogId
	  * @return
	  */
	 @AutoLog(value = "个人博客访问者-添加")
	 @ApiOperation(value="个人博客访问者-添加", notes="个人博客访问者-添加")
	 @GetMapping(value = "/addUserBlogVisitHistory")
	 public Result<?> addUserBlogVisitHistory(@RequestParam(name="blogId") String blogId) throws Exception {
		 userBlogVisitorService.addVisitHistory(blogId);
		 return Result.OK("添加成功！");
	 }
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "个人博客访问者-通过id删除")
	@ApiOperation(value="个人博客访问者-通过id删除", notes="个人博客访问者-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		userBlogVisitorService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "个人博客访问者-通过id查询")
	@ApiOperation(value="个人博客访问者-通过id查询", notes="个人博客访问者-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		UserBlogVisitor userBlogVisitor = userBlogVisitorService.getById(id);
		if(userBlogVisitor==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(userBlogVisitor);
	}
}
